import _mongo
import py2neo_class

neo_init = py2neo_class.Neo4jMod('http://localhost:7474', 'neo4j', '12345678', 'record')

# 清空数据库
neo_init.del_all_data()
print("清空neo4j完毕")

id = '4e51fa46-83ff-11ea-b826-0028f80f2700'

# 查看的face_acvs 只需要人脸的id就可以 对比记录里面也只需要在p_list里面的就可以

p_list = _mongo.getfaceacvs(id)
all_face_id = {}

for p in p_list:
    all_face_id.update({p['face_id']: p})

index = 0
for id_key, id_value in all_face_id.items():
    index += 1
    face_ovn = _mongo.get_ovn(id_key)
    node1_name = id_key
    if not face_ovn["is_front"]:
        continue
    neo_init.merge_node(node1_name)
    neo_init.update_node(node1_name, all_face_id[node1_name]['face_image_uri'], 'face_image_uri')
    neo_init.update_node(node1_name, all_face_id[node1_name]['timestamp'], 'timestamp')
    for hit_face in face_ovn['result']:
        if hit_face.get('hit_repository_id') is None:
            if hit_face['hit_face_image_id'] in all_face_id.keys():
                node2_name = hit_face['hit_face_image_id']
                if all_face_id[node2_name]["is_front"] == "False":
                    continue

                neo_init.merge_node(node2_name)
                neo_init.update_node(node2_name, all_face_id[node2_name]['face_image_uri'], 'face_image_uri')
                neo_init.update_node(node2_name, all_face_id[node2_name]['timestamp'], 'timestamp')
                neo_init.insert_side(node1_name, node2_name, 'similarity', 'similarity', hit_face['similarity'])


    # if index >= 100:
    #     break

"""
MATCH (:record { name:'c9c273d0-eb7a-4e31-ac11-33c30eda1794' })-[r:similarity]->(record)
            RETURN record.name, record.face_image_uri,record.timestamp, r.similarity;
"""
"""
match(n{name:'c9c273d0-eb7a-4e31-ac11-33c30eda1794'}) 
return n;
"""